package com.hxzy.controller.plotinfo;

import com.github.pagehelper.PageInfo;
import com.hxzy.util.DateUtils;
import com.hxzy.util.StringUtil;
import com.hxzy.util.ThreadLocalUtil;
import com.hxzy.common.BaseServlet;
import com.hxzy.dto.PlotInfoDTO;
import com.hxzy.entity.PlotInfo;
import com.hxzy.service.PlotService;
import com.hxzy.service.impl.PlotServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * @Description:
 * @Author: ykj
 * @Date: 2022/2/28 16:22
 */
@WebServlet(urlPatterns = "/web/plot")
public class PlotServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ThreadLocalUtil.threadLocal.get();
        //开启分页
        super.startPage(req);

        //收集参数（分页，每一个类都有）
        try{
            PlotInfoDTO plotInfoDTO=super.CollectiongParameterVlues(req, PlotInfoDTO.class);

            //日期
            String date = req.getParameter("beginDate");
            String date1 = req.getParameter("endDate");
            if (StringUtil.isNotBlank(date) && StringUtil.isNotBlank(date1)){
                Date beginDate = DateUtils.parseDate(date);
                Date endDate = DateUtils.parseDate(date1);
                plotInfoDTO.getParams().put("beginDate",beginDate);
                plotInfoDTO.getParams().put("endDate",endDate);
            }

            //查询
            PlotService service=new PlotServiceImpl();
            List<PlotInfo> search = service.search(plotInfoDTO);
            //输出
            super.render(resp, new PageInfo(search));


        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }


    }
}
